var express = require('express');
var async=require('async');
var router = express.Router();
var Qn=require('./QuestionNaire');
var Qna=require('./QuestionNaireAnswer');

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
router.get('/table', function(req, res, next) {
    res.render('table');
});


router.get('/GetQuestionNaires', function(req, res, next) {
    Qn.getall(res);

});
router.get('/GetQuestionNaireAnswer/:id', function(req, res, next) {
    Qna.getbyid(req.params.id,res);
});

router.post('/QuestionNairePost', function(req, res, next) {
    Qn.add(req.body);
    res.send(1);
});
router.post('/QuestionNaireAnswerPost', function(req, res, next) {
    var qnid=req.body.QnId;
    var json=JSON.stringify(req.body);
    Qna.add(json, qnid);
    res.send(1);
});

module.exports = router;



//var s="";
//function x1(){
//    console.log(1);
//    s= Qna.getbyid(req.params.id);
//}
//
//function x2(){
//    console.log(2);
//    res.json(s);
//}
//async.series([x1(),x2()],function(err, results){console.log('finish');});
//// async.auto([x1,xt,x2],function(err, results) {});